<template>
  <div>
    <!-- 保存配置 2018/3/7 11:44 zhangQ -->
    <Form :model="saveConfigForm" :label-width="100" label-position="left" @submit.native.prevent>
      <FormItem label="配置名称：">
        <i-input v-model="saveConfigForm.configName" placeholder="配置名称" style="width: 250px"></i-input>
      </FormItem>
    </Form>
    <div class="footer">
      <Button type="primary" @click="saveConfigToIndexedDB">保存配置</Button>
    </div>
  </div>
</template>

<script>
  import initDb from '@/components/common/indexeddbUtil'

  export default {
    name: 'save-config',
    data () {
      let saveConfigForm = {
        configName: ''
      }
      let datas = { saveConfigForm }
      return datas
    },
    computed: {},
    props: {
      generationForm: {
        type: Object,
        default () {
          return {}
        }
      }
    },
    methods: {
      saveConfigToIndexedDB () {
        let vue = this
        initDb(contant.storeNames.generationStore.name).then((store) => {
          let saveConfig = Object.assign({}, this.generationForm, this.saveConfigForm)
          let request = store.add(saveConfig)
          request.onsuccess = function () {
            console.log('成功')
            vue.$emit('close')
          }
          request.onerror = function (e) {
            console.log('失败')
            vue.$Notice.error({
              title: '保存失败',
              desc: '保存名称不能重复'
            })
          }
        })
      }
    },
    created () {
    },
    mounted () {
    },
    components: {}
  }
</script>

<style scoped>

</style>